package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.SkuAddNewDTO;
import cn.tedu.store.commons.pojo.product.dto.SkuUpdateFullInfoDTO;
import cn.tedu.store.commons.pojo.product.vo.SkuListItemVO;
import cn.tedu.store.commons.pojo.product.vo.SkuStandardVO;
import cn.tedu.store.product.service.ISkuService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品SKU控制器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Slf4j
@Api(tags = "10.SKU管理模块")
@RestController
@RequestMapping("/sku")
public class SkuController {

    @Autowired
    private ISkuService skuService;

    @ApiOperation("添加SKU")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(SkuAddNewDTO skuAddNewDTO){
        log.debug("开始处理[添加库存]请求 参数:{}",skuAddNewDTO);
        skuService.addNew(skuAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("修改SKU")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "SKUid", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, SkuUpdateFullInfoDTO skuUpdateFullInfoDTO){
        log.debug("开始处理[修改库存信息]请求 参数:{},{}",id ,skuUpdateFullInfoDTO);
        skuService.updateFullInfoById(id, skuUpdateFullInfoDTO);
        return JsonResult.ok();
    }

    @ApiOperation("获取SKU详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id", value = "SKUid", required = true, dataType = "long")
    @GetMapping("/{id:[0-9]+}/get-by-id")
    public JsonResult<SkuStandardVO> getStandardById(@PathVariable Long id){
        log.debug("开始处理[获取SkU详情]请求 参数:{}",id);
        return JsonResult.ok(skuService.getStandardById(id));
    }

    @ApiOperation("SKU列表")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "spuId", value = "SPUid", required = true, dataType = "long")
    @GetMapping("/{spuId:[0-9]+}/list-by-spu")
    public JsonResult<List<SkuListItemVO>> list(@PathVariable Long spuId) {
        log.debug("开始处理[获取SKU列表]请求 参数:{}",spuId);
        return JsonResult.ok(skuService.list(spuId));
    }
}
